﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;

/// <summary>
///Mail 的摘要说明
/// </summary>
public class Mail
{
	public Mail()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    #region 发送邮件，产生随机密码。
    /// <summary>
    /// 发送邮件，产生随机密码。
    /// </summary>
    /// <param name="mail"></param>
    /// <param name="name"></param>
    public static void sendMail(string mail, string name)
    {
        string pwd = Mail.random();
        MailMessage mailmessage = new MailMessage();
        mailmessage.From = new MailAddress("test@test.com", "广东药学院失物招领网");
        mailmessage.To.Add(new MailAddress(mail, name));
        mailmessage.Subject = "广东药学院失物招领网";
        mailmessage.Body = "这是广东药学院失物招领网为您重置的密码" + pwd + "<a href='http://localhost:10742/web/activepwd.ashx?pwd=" + pwd + "&name=" + name + "'>请您点击这里激活该密码。</a>";
        //mailmessage.Body = "<a href='http://www.baidu.com'>密码</a>";
        mailmessage.IsBodyHtml = true;
        //简单邮件传输协议服务器
        //SmtpClient client = new SmtpClient("smtp.qq.com");
        SmtpClient client = new SmtpClient("127.0.0.1");
        client.Credentials = new NetworkCredential("test", "123abc");
        client.Send(mailmessage);
    }
    #endregion


    #region  产生随机密码串 
    /// <summary>
    /// 产生随机密码串
    /// </summary>
    /// <returns></returns>
    public static string random()
    {
        Random r = new Random();
        string s = "";
        for (int i = 0; i < 6; i++)
        {
            s += r.Next(0, 9).ToString();
        }
        return s;
    } 
    #endregion
}